package controllers;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import beans.Aeroport;
import beans.VolReel;
import dao.DaoAeroport;
import dao.DaoVolReel;
import dao.HibernateUtil;
import dao.interfaces.IDaoVolReel;
import dao.interfaces.IdaoAeroport;

@Controller
public class ControllerHome {

	@RequestMapping(value = "/home")
	public ModelAndView home() {
		
		ModelAndView mv = new ModelAndView();
		IdaoAeroport dao = new DaoAeroport();
		HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
		
		List<Aeroport> liste = dao.getAll();
		
		HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();
		
		mv.addObject("listeAeroport",liste);
		
		mv.setViewName("index");
		return mv;
	}


	@RequestMapping(value = "/faq")
	public ModelAndView faq() {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("faq");
		return mv;
	}	

	// La page d'index redirige vers /home
	@RequestMapping(value = "/")
	public String redirect() {
		return "redirect:/home";
	}

	// La page erreur 404, tomcat redirige tout seul les 404 vers / erreur (voir
	// web.xml)
	@RequestMapping(value = "/error")
	public ModelAndView error404() {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("frontOffice/error");
		return mv;
	}

}
